﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp.多线程
{ 
   public  class TaskDemoE
    {
        public static void Main_test()
        {
            ThreadStart num = new ThreadStart(PrintNum);
            Thread ConstrolNum = new Thread(num);
            ThreadStart str = new ThreadStart(PrintStr);
            Thread ConstrolStr = new Thread(str);
            Stopwatch watch = new Stopwatch();
            watch.Start();
            ConstrolNum.Start();
            ConstrolStr.Start();
            while (true)
            {
                if (ConstrolNum.ThreadState == System.Threading.ThreadState.Stopped && ConstrolStr.ThreadState == System.Threading.ThreadState.Stopped)
                {
                    watch.Stop();
                    Console.WriteLine(watch.Elapsed.TotalMilliseconds);
                    break;
                }
            }
            Console.ReadKey();
        }
        private static void PrintNum()
        {
            for (int i = 1; i < 1000; i++)
            {
                Console.WriteLine(i);
            }
        }
        private static void PrintStr()
        {
            for (int i = 1; i < 1000; i++)
            {
                Console.WriteLine("当前数为:{0}", i);
            }
        }
    }
}
